﻿package org.xhs.report.common.ui
{
    import baidu.ui.managers.*;
    import baidu.wenku.common.*;
    import baidu.wenku.common.model.*;
    import baidu.wenku.common.utils.*;
    import baidu.wenku.doc.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;

    public class BookmarkBar extends Sprite
    {
        protected var bmw:Number;
        protected var bmh:Number;
        protected var bmi:Sprite;
        protected var _bookmarkBtn:Sprite;
        protected var _bookmarkInterval:uint;
        protected var loaderInfoVo:LoaderInfoVO;
        protected var screenModel:ScreenModel;
        public static const BOOKMARK_CLICK:String = "BOOKMARK_CLICK";

        public function BookmarkBar()
        {
            this.init();
            return;
        }// end function

        protected function init() : void
        {
            this.loaderInfoVo = InstanceManager.createSingletonInstance(LoaderInfoVO);
            this.screenModel = InstanceManager.createSingletonInstance(ScreenModel);
            this.screenModel.addEventListener(Event.RESIZE, this.screenResize);
            this.bmw = this.screenModel.stageWidth - Config.DV_WIDTH_RIGHT_SCROLLBAR - (Config.docType == Config.DOC_TYPE_TXT ? (1) : (DocConfig.DV_WIDTH_LEFT_PADDING + DocConfig.DV_WIDTH_RIGHT_PADDING));
            this.bmh = 30;
            return;
        }// end function

        protected function screenResize(event:Event) : void
        {
            this.bmw = this.screenModel.stageWidth - Config.DV_WIDTH_RIGHT_SCROLLBAR - (Config.docType == Config.DOC_TYPE_TXT ? (1) : (DocConfig.DV_WIDTH_LEFT_PADDING + DocConfig.DV_WIDTH_RIGHT_PADDING));
            this.removeBar();
            return;
        }// end function

        protected function bookmarkMouseHandler(event:MouseEvent) : void
        {
            if (!this._bookmarkBtn)
            {
                return;
            }
            var _loc_2:* = this._bookmarkBtn.graphics;
            switch(event.type)
            {
                case MouseEvent.ROLL_OVER:
                {
                    _loc_2.clear();
                    _loc_2.lineStyle();
                    _loc_2.beginFill(16773601);
                    _loc_2.drawRect(0, 0, (this.bmw - 1), this.bmh);
                    _loc_2.endFill();
                    _loc_2.lineStyle(1, 16173854);
                    _loc_2.moveTo(0, this.bmh);
                    _loc_2.lineTo((this.bmw - 1), this.bmh);
                    break;
                }
                case MouseEvent.ROLL_OUT:
                {
                    _loc_2.clear();
                    _loc_2.lineStyle();
                    _loc_2.beginFill(16775666);
                    _loc_2.drawRect(0, 0, (this.bmw - 1), this.bmh);
                    _loc_2.endFill();
                    _loc_2.lineStyle(1, 16173854);
                    _loc_2.moveTo(0, this.bmh);
                    _loc_2.lineTo((this.bmw - 1), this.bmh);
                    break;
                }
                case MouseEvent.CLICK:
                {
                    WenkuLog.addLog(WenkuLog.LOGURL_BOOKMARKCLICK);
                    dispatchEvent(new Event(BOOKMARK_CLICK));
                    this.loaderInfoVo.bookmarkPage = 0;
                    this.hide();
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        protected function removeBar(event:Event = null) : void
        {
            if (!this._bookmarkBtn)
            {
                return;
            }
            while (this._bookmarkBtn.numChildren > 0)
            {
                
                this._bookmarkBtn.removeChildAt(0);
            }
            if (contains(this._bookmarkBtn))
            {
                removeChild(this._bookmarkBtn);
            }
            this._bookmarkBtn.removeEventListener(MouseEvent.ROLL_OVER, this.bookmarkMouseHandler);
            this._bookmarkBtn.removeEventListener(MouseEvent.ROLL_OUT, this.bookmarkMouseHandler);
            this._bookmarkBtn.removeEventListener(MouseEvent.CLICK, this.bookmarkMouseHandler);
            this._bookmarkBtn = null;
            return;
        }// end function

        public function showNewMarkInfo(param1:String, param2:int = 0) : void
        {
            if (this._bookmarkBtn)
            {
                while (this._bookmarkBtn.numChildren > 0)
                {
                    
                    this._bookmarkBtn.removeChildAt(0);
                }
                if (contains(this._bookmarkBtn))
                {
                    removeChild(this._bookmarkBtn);
                }
            }
            else
            {
                this._bookmarkBtn = new Sprite();
            }
            this._bookmarkBtn.mouseEnabled = false;
            this._bookmarkBtn.mouseChildren = true;
            var _loc_3:* = this._bookmarkBtn.graphics;
            _loc_3.clear();
            _loc_3.lineStyle();
            _loc_3.beginFill(16775666);
            _loc_3.drawRect(0, 0, (this.bmw - 1), this.bmh);
            _loc_3.endFill();
            _loc_3.lineStyle(1, 16173854);
            _loc_3.moveTo(0, this.bmh);
            _loc_3.lineTo((this.bmw - 1), this.bmh);
            switch(param2)
            {
                case 1:
                {
                    this.bmi = new BookMarkIcon2() as Sprite;
                    break;
                }
                default:
                {
                    this.bmi = new BookMarkIcon() as Sprite;
                    break;
                    break;
                }
            }
            this._bookmarkBtn.addChild(this.bmi);
            this.bmi.x = 14;
            this.bmi.y = (this.bmh - this.bmi.height) / 2;
            var _loc_4:* = new TextField();
            var _loc_5:* = new StyleSheet();
            new StyleSheet().setStyle("a:hover", {textDecoration:"underline", color:"#003399"});
            _loc_5.setStyle("a:link", {textDecoration:"none", color:"#003399"});
            _loc_4.selectable = false;
            _loc_4.autoSize = "left";
            if (param1)
            {
                _loc_4.htmlText = param1;
            }
            else
            {
                return;
            }
            _loc_4.styleSheet = _loc_5;
            this._bookmarkBtn.addChild(_loc_4);
            _loc_4.x = 35;
            _loc_4.y = (this.bmh - _loc_4.height) / 2;
            addChild(this._bookmarkBtn);
            this._bookmarkBtn.x = Config.docType == Config.DOC_TYPE_TXT ? (1) : (DocConfig.DV_WIDTH_LEFT_PADDING + 2);
            this._bookmarkBtn.y = Config.TB_HEIGHT;
            clearInterval(this._bookmarkInterval);
            this._bookmarkInterval = setInterval(this.hide, 5000);
            return;
        }// end function

        public function show() : void
        {
            WenkuLog.addLog(WenkuLog.LOGURL_BOOKMARKVIEW);
            if (!this._bookmarkBtn)
            {
                this._bookmarkBtn = new Sprite();
            }
            var _loc_1:* = this._bookmarkBtn.graphics;
            _loc_1.clear();
            _loc_1.lineStyle();
            _loc_1.beginFill(16775666);
            _loc_1.drawRect(0, 0, (this.bmw - 1), this.bmh);
            _loc_1.endFill();
            _loc_1.lineStyle(1, 16173854);
            _loc_1.moveTo(0, this.bmh);
            _loc_1.lineTo((this.bmw - 1), this.bmh);
            this.bmi = new BookMarkIcon() as Sprite;
            this._bookmarkBtn.addChild(this.bmi);
            this.bmi.x = 14;
            this.bmi.y = 8;
            var _loc_2:* = new TextField();
            var _loc_3:* = new TextFormat("宋体", 12, 13209);
            _loc_2.selectable = false;
            _loc_2.autoSize = "left";
            _loc_2.htmlText = "<FONT FACE=\"宋体\" SIZE=\"12\" COLOR=\"#000000\">您上次阅读到此页，点击这里返回第一页</FONT>";
            this._bookmarkBtn.addChild(_loc_2);
            _loc_2.x = 35;
            _loc_2.y = (this.bmh - _loc_2.height) / 2;
            addChild(this._bookmarkBtn);
            this._bookmarkBtn.x = Config.docType == Config.DOC_TYPE_TXT ? (1) : (DocConfig.DV_WIDTH_LEFT_PADDING + 2);
            this._bookmarkBtn.y = Config.TB_HEIGHT;
            this._bookmarkBtn.mouseChildren = false;
            this._bookmarkBtn.buttonMode = true;
            this._bookmarkBtn.addEventListener(MouseEvent.ROLL_OVER, this.bookmarkMouseHandler);
            this._bookmarkBtn.addEventListener(MouseEvent.ROLL_OUT, this.bookmarkMouseHandler);
            this._bookmarkBtn.addEventListener(MouseEvent.CLICK, this.bookmarkMouseHandler);
            clearInterval(this._bookmarkInterval);
            this._bookmarkInterval = setInterval(this.hide, 5000);
            return;
        }// end function

        public function hide() : void
        {
            var rid:int;
            clearInterval(this._bookmarkInterval);
            if (this._bookmarkBtn)
            {
                rid = setInterval(function () : void
            {
                if (!_bookmarkBtn)
                {
                    clearInterval(rid);
                }
                else
                {
                    _bookmarkBtn.alpha = _bookmarkBtn.alpha - 0.1;
                    _bookmarkBtn.y = _bookmarkBtn.y - 2;
                    if (_bookmarkBtn.alpha <= 0.1)
                    {
                        clearInterval(rid);
                        if (_bookmarkBtn)
                        {
                            removeBar();
                        }
                    }
                }
                return;
            }// end function
            , 10);
            }
            return;
        }// end function

    }
}
